#include <OneWire.h>
#include <Arduino.h>
#include <EEPROM.h>
#include <DallasTemperature.h>
#include <GravityTDS.h>

#define Ds18b20Pin 5  // 定义ESP8266的引脚D5
#define TdsSensorPin 6

GravityTDS gravityTds;

float temperature = 25, tdsValue = 0;
OneWire oneWire(Ds18b20Pin);
OneWire tdsOneWire(TdsSensorPin);
DallasTemperature tmpSensors(&oneWire);
DallasTemperature tdsSensors(&oneWire);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  tmpSensors.begin();
  tdsSensors.begin();
  gravityTds.setPin(TdsSensorPin);
  gravityTds.setAref(5.0);       //reference voltage on ADC, default 5.0V on Arduino UNO
  gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
  gravityTds.begin();            //initialization
}

void loop() {
  // put your main code here, to run repeatedly:
  float temperature = getTempV2();
  Serial.println(temperature);
  float tds = getTds();
  Serial.println(tds);
  delay(1000);
}

float getTempV2() {
  tmpSensors.requestTemperatures();
  float t = tmpSensors.getTempCByIndex(0);  // 获取采集温度
  Serial.println("The Temperature:");
  Serial.println(t);
  Serial.println(" *C");
}

float getTds(){
    //temperature = readTemperature();  //add your temperature sensor and read it
  gravityTds.setTemperature(temperature);  // set the temperature and execute temperature compensation
  gravityTds.update();                     //sample and calculate
  tdsValue = gravityTds.getTdsValue();     // then get the value
  Serial.print(tdsValue, 0);
  Serial.println("ppm");
}

